package com.infolab.aims.web;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperRunManager;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.infolab.aims.GlobalConstant;
import com.infolab.aims.common.AbstractController;
import com.infolab.aims.common.CommonUtil;
import com.infolab.aims.common.InQueryHelper;
import com.infolab.aims.common.ParameterDateQueryHelper;
import com.infolab.aims.common.bean.SearchCriteria;
import com.infolab.aims.common.bean.SearchResult;
import com.infolab.aims.common.exception.ResourceNotFoundException;
import com.infolab.aims.domain.Department;
import com.infolab.aims.domain.SystemUser;
import com.infolab.aims.domain.Vehicle;
import com.infolab.aims.domain.asset.AssetModel;
import com.infolab.aims.domain.workorder.WorkOrder;
import com.infolab.aims.domain.workorder.WorkOrderDetail;
import com.infolab.aims.domain.workorder.WorkOrderPart;
import com.infolab.aims.domain.workorder.WorkOrderTechnician;
import com.infolab.aims.service.intf.AssetModelService;
import com.infolab.aims.service.intf.SystemUserService;
import com.infolab.aims.service.intf.VehicleService;
import com.infolab.aims.service.intf.WorkOrderServiceFacade;

@Controller
@RequestMapping("/workOrder")
@SessionAttributes(value=WorkOrderController.SESSION_SEARCH_CRITERIA)
public class WorkOrderController extends AbstractController {

	public static final String SESSION_SEARCH_CRITERIA ="workOrderSearchCriteria";
	public static final String CONTEXT_PATH ="/workOrder";
	public static final String JSP_MAIN_FORM="workOrderForm";
	public static final String JSP_MAIN_FORM_POPUP="workOrderFormPopUp";
	public static final String JSP_WORK_ORDER_FORM2="workOrderForm2";
	public static final String JSP_WORK_ORDER_FORM2_POPUP="workOrderForm2PopUp";
	
	public static final String JSP_CLOCK_IN_OUT_FORM="clockInOutForm";
	public static final String JSP_MAIN_SEARCH="workOrderSearch";
	public static final String JSP_EDIT_TIME_FORM="editWorkOrderTimeForm";
	
	
	
	@Autowired
	WorkOrderServiceFacade workOrderServiceFacade;

	@Autowired
	AssetModelService assetModelService;

	@Autowired
	SystemUserService systemUserService;

	@Autowired
	VehicleService vehicleService;

	Log logger = LogFactory.getLog(getClass());
	
	private void populateWorkOrderForm(Model model)
	{
		SearchCriteria searchCriteria = new SearchCriteria();
		searchCriteria.addSearchCriteria("assetType", AssetModel.ASSETTYPE_EQUIPMENT);
		List<AssetModel> assetModels = assetModelService.findAssetModels(searchCriteria);
		model.addAttribute(assetModels);
	}

	@RequestMapping(value="create", method = RequestMethod.GET)
	public String createWorkOrder(Model model,HttpServletRequest request) {
		populateWorkOrderForm(model);
		WorkOrder workOrder = new WorkOrder();
		workOrder.setWorkOrderType(WorkOrder.WORKORDERTYPE_WALKIN);
		workOrder.setAccessDepartment(getCurrentDepartment(request));
		model.addAttribute(workOrder);
		return JSP_MAIN_FORM;
	}

	@RequestMapping(value="create",method=RequestMethod.POST)
	public String saveWorkOrder(@ModelAttribute WorkOrder workOrder, BindingResult result,Model model,HttpServletRequest request) {

		populateWorkOrderForm(model);

		if (validateWorkOrder(workOrder, result)) {	
			return JSP_MAIN_FORM;
		}
		
		workOrder.setCreatedBy(getCurrentUserName(request));

		workOrderServiceFacade.createWorkOrder(workOrder);

		setSuccessMessage(getMessageResources("success.create","workOrder " + workOrder.getWorkOrderCode()));

		refreshGlobalSection(request);

		
		return "redirect:"+CONTEXT_PATH+"/update/" + workOrder.getWorkOrderId()+"?tab=2";


	}

	@RequestMapping(value="reassign/{id}",method=RequestMethod.GET)
	public @ResponseBody WorkOrderTechnician reassignTehnician(@PathVariable Integer id,@RequestParam(value="userName") String userName) {

		WorkOrderTechnician workOrderTechnician = new WorkOrderTechnician();
		WorkOrder workOrder = new WorkOrder();
		workOrder.setWorkOrderId(id);
		workOrderTechnician.setWorkOrder(workOrder);
		SystemUser technician = systemUserService.getUser(userName);
		workOrderTechnician.setTechnician(technician);
		workOrderServiceFacade.updateWorkOrderTecnician(workOrderTechnician);

		return workOrderTechnician;
	}

	@RequestMapping(value="update/{id}",method=RequestMethod.POST)
	public String updateWorkOrder(@PathVariable Integer id,@ModelAttribute WorkOrder workOrder, BindingResult result,Model model,HttpServletRequest request) {

		populateWorkOrderForm(model);

		if (validateWorkOrder(workOrder, result)) {
			return JSP_MAIN_FORM;
		}
		
		workOrder.setModifiedBy(getCurrentUserName(request));

		workOrderServiceFacade.updateWorkOrder(workOrder);
		setSuccessMessage(getMessageResources("success.update","workOrder " + workOrder.getWorkOrderCode()));

		return "redirect:"+CONTEXT_PATH+"/update/" + workOrder.getWorkOrderId()+getUrlforTabAndPopUp(request);	

	}
	
	
	private String getUrlforTabAndPopUp(HttpServletRequest request)
	{
		String urlTab ="";
		if(StringUtils.isNotEmpty(request.getParameter("tab")))
		{
			urlTab = "?tab=2";
		}
		
		String popUp = request.getParameter("popUpFlag")!=null? (String)request.getParameter("popUpFlag"):"";
		if(popUp.equalsIgnoreCase("Y")){
			if(!StringUtils.isEmpty(urlTab))
				urlTab = urlTab + "&popUpFlag=Y";
			else
				urlTab = "?popUpFlag=Y";
		}
		
		return urlTab;
	}

	@RequestMapping(value="close/{id}",method=RequestMethod.POST)
	public String closeWorkOrder(@PathVariable Integer id,@ModelAttribute WorkOrder workOrder, BindingResult result,Model model,HttpServletRequest request) {

		populateWorkOrderForm(model);

		if (validateWorkOrder(workOrder, result)) {
			return JSP_MAIN_FORM;
		}
		
		workOrder.setModifiedBy(getCurrentUserName(request));

		workOrderServiceFacade.closeWorkOrder(workOrder);

		setSuccessMessage(getMessageResources("success.close","workOrder " + workOrder.getWorkOrderCode()));

		return "redirect:"+CONTEXT_PATH+"/update/" + workOrder.getWorkOrderId()+getUrlforTabAndPopUp(request);	

	}
	
	@RequestMapping(value="cancel/{id}",method=RequestMethod.POST)
	public String cancelWorkOrder(@PathVariable Integer id,@ModelAttribute WorkOrder workOrder, BindingResult result,Model model,HttpServletRequest request) {

		populateWorkOrderForm(model);

		if (validateWorkOrder(workOrder, result)) {
			return JSP_MAIN_FORM;
		}
		
		workOrder.setModifiedBy(getCurrentUserName(request));

		workOrderServiceFacade.cancelWorkOrder(workOrder);
		
		setSuccessMessage(getMessageResources("success.cancel","workOrder " + workOrder.getWorkOrderCode()));


		return "redirect:"+CONTEXT_PATH+"/update/" + workOrder.getWorkOrderId()+getUrlforTabAndPopUp(request);	

	}

	@RequestMapping(value={"update/{id}","detail/{id}"}, method = RequestMethod.GET)
	public String detailWorkOrder(@PathVariable Integer id,Model model,HttpServletRequest request) {

		WorkOrder workOrder = workOrderServiceFacade.getWorkOrder(id);
		if(workOrder==null) {
			throw new ResourceNotFoundException("WorkOrder " + id);
		}

		populateWorkOrderForm(model);

		model.addAttribute(workOrder);

		String popUp = request.getParameter("popUpFlag")!=null? (String)request.getParameter("popUpFlag"):"";
		
		if(StringUtils.isNotEmpty(request.getParameter("tab")))
		{
			if(popUp.equalsIgnoreCase("Y")){
				model.addAttribute("popUpFlag","Y");
				return JSP_WORK_ORDER_FORM2_POPUP;
			}
			return JSP_WORK_ORDER_FORM2;
		}
		
		
		if(popUp.equalsIgnoreCase("Y")){
			model.addAttribute("popUpFlag","Y");
			return JSP_MAIN_FORM_POPUP;
		}
		return JSP_MAIN_FORM;

	}
	
	@RequestMapping(value="editWorkOrderTime/{id}", method = RequestMethod.GET)
	public String editWorkOrderTime(@PathVariable Integer id,Model model,HttpServletRequest request) {

		WorkOrder workOrder = workOrderServiceFacade.getWorkOrder(id);
		if(workOrder==null) {
			throw new ResourceNotFoundException("WorkOrder " + id);
		}
		
		int techId = request.getParameter("techId")!=null? Integer.valueOf(request.getParameter("techId")):-1;
		WorkOrderTechnician workOrderTechnician =  workOrderServiceFacade.getWorkOrderTechnician(techId);
		
		if(workOrderTechnician==null) {
			throw new ResourceNotFoundException("workOrderTechnician " + techId);
		}
		String success = request.getParameter("success")!=null? (String)request.getParameter("success"):"";
		if(success.equalsIgnoreCase("Y")){
			model.addAttribute("success","Y");
		}
		populateWorkOrderForm(model);
		model.addAttribute(workOrderTechnician);
		return JSP_EDIT_TIME_FORM;
	}
	
	@RequestMapping(value="editWorkOrderTime/{id}",method=RequestMethod.POST)
	public String updateEditWorkOrderTime(@ModelAttribute WorkOrderTechnician workOrderTechnician, BindingResult result,Model model,HttpServletRequest request) {

		
		SimpleDateFormat formatter = new SimpleDateFormat(GlobalConstant.DATE_FORMAT_JAVA);
		String  start = formatter.format(workOrderTechnician.getWorkOrder().getDateBooking()) + " "+workOrderTechnician.getStartTm();
		String  end = formatter.format(workOrderTechnician.getWorkOrder().getDateBooking()) + " "+workOrderTechnician.getEndTm();
		
		SimpleDateFormat fmtWithTime = new SimpleDateFormat(GlobalConstant.DATE_TIME_FORMAT_JAVA); 
		
		try {
			workOrderTechnician.setTimeStart(fmtWithTime.parse(start));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		try {
			workOrderTechnician.setTimeEnd(fmtWithTime.parse(end));
		} catch (ParseException e) {
			e.printStackTrace();			
		}
		workOrderTechnician.setModifiedBy(getCurrentUserName(request));
		workOrderServiceFacade.updateWorkOrderTecnicianTime(workOrderTechnician);
		model.addAttribute("success", "Y");
		setSuccessMessage(getMessageResources("success.update","work order Time for " + workOrderTechnician.getTechnician().getPersonName()));
		return "redirect:"+CONTEXT_PATH+"/editWorkOrderTime/"+workOrderTechnician.getWorkOrder().getWorkOrderId()+"?techId="
					+workOrderTechnician.getWorkOrderTechnicianId();	
	}
	

	@InitBinder
	public void initBinder(WebDataBinder binder) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		dateFormat.setLenient(false);
		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
	}


	@ModelAttribute(WorkOrderController.SESSION_SEARCH_CRITERIA)
	public SearchCriteria getWorkOrderSearchCriteria()
	{
		return new SearchCriteria();
	}


	@RequestMapping(value="search")
	public String searchWorkOrder(@ModelAttribute(WorkOrderController.SESSION_SEARCH_CRITERIA) SearchCriteria searchCriteria,@ModelAttribute("currentSearchCriteria") SearchCriteria currentSearchCriteria,Model model,HttpServletRequest request) {

		Department accessDepartment = getCurrentDepartment(request);
		if(accessDepartment !=null)
			searchCriteria.addSearchCriteria("accessDepartmentId", accessDepartment.getDepartmentId());
		
		if(currentSearchCriteria.getCurPage()!=null)
			searchCriteria.setCurPage(currentSearchCriteria.getCurPage());

		if(currentSearchCriteria.getSortName()==null)
		{
			searchCriteria.setSortName("workOrderCode");
			searchCriteria.setSortType(SearchCriteria.SORTTYPE_DESC);
		}
		
		Date dateFrom = null;
		Date dateTo = null;
		
		try{
			if(!checkNullEmpty(searchCriteria.getSearchCriteria("startBookingDate"))) {			 
				dateFrom = new SimpleDateFormat(GlobalConstant.DATE_FORMAT_JAVA).parse(searchCriteria.getSearchCriteria("startBookingDate").toString());
			}
		}
		catch (ParseException e) {
			searchCriteria.addSearchCriteria("startBookingDate", "");
		}
		
		try{
			
			if(!checkNullEmpty(searchCriteria.getSearchCriteria("endBookingDate"))) {			  
				dateTo= new SimpleDateFormat(GlobalConstant.DATE_FORMAT_JAVA).parse(searchCriteria.getSearchCriteria("endBookingDate").toString());
			}
		}
		catch (ParseException e) {
			searchCriteria.addSearchCriteria("endBookingDate", "");
		}

		if(!checkNullEmpty(dateFrom) &&  !checkNullEmpty(dateTo)) {
			searchCriteria.addSearchCriteria("dateBooking", new ParameterDateQueryHelper("dateBooking", dateFrom,dateTo));
		}
		
		else if(!checkNullEmpty(dateFrom) &&  checkNullEmpty(dateTo)){
			searchCriteria.addSearchCriteria("dateBooking", new ParameterDateQueryHelper("dateBooking", dateFrom, null));
		}		
		else if(checkNullEmpty(dateFrom) &&  !checkNullEmpty(dateTo)){
			searchCriteria.addSearchCriteria("dateBooking", new ParameterDateQueryHelper("dateBooking", null, dateTo));
		}	
		else {
			searchCriteria.addSearchCriteria("dateBooking", new ParameterDateQueryHelper("dateBooking", null, null));
		}
		
		SearchResult searchResult = workOrderServiceFacade.searchWorkOrder(searchCriteria);
		model.addAttribute(searchResult);

		return JSP_MAIN_SEARCH;
	}
	
	public boolean checkNullEmpty(Object obj){
		
		boolean flag=true;
		if(obj!=null && !obj.equals("")){
			flag = false;
		}
		return flag;
	
	}

	@RequestMapping(value={"delete/{id}"}, method = RequestMethod.GET)
	public String deleteWorkOrder(@PathVariable Integer id,Model model,HttpServletRequest request) {

		workOrderServiceFacade.deleteWorkOrder(id);

		refreshGlobalSection(request);

		return "redirect:"+CONTEXT_PATH+"/search";
	}

	@RequestMapping(value={"print/{id}"}, method = RequestMethod.GET)
	public void printWorkOrder(@PathVariable Integer id,Model model,HttpServletRequest request,HttpServletResponse response) throws IOException {

		try
		{
			ServletOutputStream servletOutputStream = response.getOutputStream();
			InputStream reportStream =getClass().getClassLoader().getResourceAsStream("report/WorkOrderForm.jasper");
			List list = new ArrayList<WorkOrder>();
			WorkOrder workOrder = workOrderServiceFacade.getWorkOrder(id);
			
			if(workOrder.getAssetModelCode()==null)
				workOrder.setAssetModelCode("");
			if(workOrder.getMeVersion()==null)
				workOrder.setMeVersion("");
			
			if((workOrder.getWorkOrderComplaints()==null || workOrder.getWorkOrderComplaints().size()==0) && 
					(workOrder.getWorkOrderRepairs()==null  || workOrder.getWorkOrderRepairs().size()==0) && 
					(workOrder.getWorkOrderParts()==null  || workOrder.getWorkOrderParts().size()==0) )
			{
				workOrder.setWorkOrderRepairs(Arrays.asList(new WorkOrderDetail(),new WorkOrderDetail(),new WorkOrderDetail(),new WorkOrderDetail(),new WorkOrderDetail())); 
				workOrder.setWorkOrderComplaints(Arrays.asList(new WorkOrderDetail(),new WorkOrderDetail(),new WorkOrderDetail()));
				workOrder.setWorkOrderParts(Arrays.asList(new WorkOrderPart(),new WorkOrderPart(),new WorkOrderPart()));				
			}
			if((workOrder.getWorkOrderComplaints()==null || workOrder.getWorkOrderComplaints().size()==0))
			{
				workOrder.setWorkOrderComplaints(Arrays.asList(new WorkOrderDetail(),new WorkOrderDetail()));
			}
			if((workOrder.getWorkOrderRepairs()==null  || workOrder.getWorkOrderRepairs().size()==0))
			{
				if((workOrder.getWorkOrderParts()==null  || workOrder.getWorkOrderParts().size()==0))
					workOrder.setWorkOrderRepairs(Arrays.asList(new WorkOrderDetail(),new WorkOrderDetail(),new WorkOrderDetail(),new WorkOrderDetail(),new WorkOrderDetail()));
				else
					workOrder.setWorkOrderRepairs(Arrays.asList(new WorkOrderDetail(),new WorkOrderDetail(),new WorkOrderDetail(),new WorkOrderDetail()));
			}
			if((workOrder.getWorkOrderParts()==null  || workOrder.getWorkOrderParts().size()==0))
			{
				workOrder.setWorkOrderParts(Arrays.asList(new WorkOrderPart(),new WorkOrderPart(),new WorkOrderPart()));
			}
			
			list.add(workOrder);
			
			JasperRunManager.runReportToPdfStream(reportStream,
					servletOutputStream,
					new HashMap(),
					new JRBeanCollectionDataSource(list));
			response.setContentType("application/pdf");
			servletOutputStream.flush();
			servletOutputStream.close();
		}
		catch (JRException e)
		{
			logger.error(CommonUtil.getStackTrace(e));
			// display stack trace in the browser
			StringWriter stringWriter = new StringWriter();
			PrintWriter printWriter = new PrintWriter(stringWriter);
			e.printStackTrace(printWriter);
			response.setContentType("text/plain");
			response.getOutputStream().print(stringWriter.toString());
		}

	}


	private boolean validateWorkOrder(WorkOrder workOrder,BindingResult result)
	{
		if(workOrder.getAccessDepartment().getDepartmentId()==null)
			workOrder.setAccessDepartment(null);
		
		if(StringUtils.isEmpty(workOrder.getVehicleId()))
			workOrder.setVehicleId(null);
		else
		{
			Vehicle vehicle = vehicleService.getVehicle(workOrder.getVehicleId());
			if(vehicle==null)
				workOrder.setVehicleId(null);
		}
		
		validator.validate(workOrder, result);
		
		if(!result.hasErrors() && workOrder.getWorkOrderId()==null)
		{
			SearchCriteria searchCriteria = new SearchCriteria();
			searchCriteria.addSearchCriteria("workOrderStatus",new InQueryHelper("workOrderStatus",Arrays.asList(new String[]{WorkOrder.WORKORDERSTATUS_INQUEUE,WorkOrder.WORKORDERSTATUS_INPROCESS,workOrder.WORKORDERSTATUS_COMPLETED})) );
			searchCriteria.addSearchCriteria("vehicleId", workOrder.getVehicleId());
			WorkOrder tmp = workOrderServiceFacade.findWorkOrder(searchCriteria);
			if(tmp!=null)
			{
				result.reject("error.workOrder.notClosed", new String[]{workOrder.getVehicleId()}, "");
			}
			
		}
		

		return result.hasErrors();
	}

	private boolean validateClockInOut(WorkOrderTechnician workOrderTechnician,BindingResult result)
	{
		String technicianNric = workOrderTechnician.getTechnician().getNric();

		SearchCriteria searchCriteria = new SearchCriteria();
		searchCriteria.addSearchCriteria("workOrderCode", workOrderTechnician.getWorkOrder().getWorkOrderCode());
		WorkOrder workOrder = workOrderServiceFacade.findWorkOrder(searchCriteria);

		workOrderTechnician.setWorkOrder(workOrder);

		
		
		if(workOrder==null)
			result.reject("error.clockInOut.noWorkOrder");
		else
		{
			if(!workOrder.isWorkOrderStatusInQueue() && !workOrder.isWorkOrderStatusInProcess())
				result.reject("error.clockInOut.completed");
			else
			{
				if( workOrder.getTimeCheckIn()!=null)
				{
				Long timeIn = workOrder.getTimeCheckIn().getTime()+(60*3*1000);
				Long timeOut = new Date().getTime();
				if(timeIn>timeOut)
					result.reject("error.clockInOut.timeProblem");
				}
			}
		}
		
		 


		if(!result.hasErrors())
		{
			searchCriteria.addSearchCriteria("nric", technicianNric);
			if(workOrder.getTechnician()==null)
			{
				SystemUser technician = systemUserService.findUser(searchCriteria);
	
				workOrderTechnician.setTechnician(technician);
	
				if(technician==null)
				{
					result.reject("error.clockInOut.noTechnician");
				}
			}
			else
				workOrderTechnician.setTechnician(workOrder.getTechnician());
		}


		return result.hasErrors();
	}

	@RequestMapping(value="clockInOut", method = RequestMethod.GET)
	public String createClockInOut(Model model,HttpServletRequest request) {

		WorkOrderTechnician workOrderTechnician = new WorkOrderTechnician();

		if(request.getSession().getAttribute("workOrderTechnician")!=null)
		{
			workOrderTechnician = (WorkOrderTechnician) request.getSession().getAttribute("workOrderTechnician");
			request.getSession().removeAttribute("workOrderTechnician");
		}

		model.addAttribute(workOrderTechnician);

		return JSP_CLOCK_IN_OUT_FORM;
	}

	@RequestMapping(value="clockInOut", method = RequestMethod.POST)
	public String updateClockInOut(@ModelAttribute WorkOrderTechnician workOrderTechnician, BindingResult result,Model model,HttpServletRequest request) {

		if (validateClockInOut(workOrderTechnician, result)) {
			return JSP_CLOCK_IN_OUT_FORM;
		}
		//			
		workOrderServiceFacade.updateClockInOut(workOrderTechnician);


		model.addAttribute(workOrderTechnician);

		if(workOrderTechnician.getWorkOrder().getTimeCheckOut()!=null)
			setSuccessMessage(getMessageResources("success.workOrder.clockOut")+" - Technician: "+workOrderTechnician.getTechnician().getNric()+" for Work Order: "
					+workOrderTechnician.getWorkOrder().getWorkOrderCode());
		else
			setSuccessMessage(getMessageResources("success.workOrder.clockIn")+" - Technician: "+workOrderTechnician.getTechnician().getNric()+" for Work Order: "
			+workOrderTechnician.getWorkOrder().getWorkOrderCode());

		
		//Prepare the page for next scan by assigning null to work order and nric 
		workOrderTechnician.setWorkOrder(null);
		workOrderTechnician.getTechnician().setNric(null);
		request.getSession().setAttribute("workOrderTechnician", workOrderTechnician);

		return "redirect:"+CONTEXT_PATH+"/clockInOut";
	}

	private boolean validateWorkOrderAssets(WorkOrder workOrder,BindingResult result)
	{
		//		if(workOrder.getSection().getSectionId()==null)
		//			workOrder.setSection(null);

		//		validator.validate(workOrder, result);

		return result.hasErrors();
	}
}
